﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace BakalarskaPraca.Generation.Data
{
    public class PlantLibrary
    {
        private List<PlantData> _plants = new List<PlantData>();
        public string Name;

        public PlantLibrary(string dataLibraryPath)
        {
            this.LoadDataLibrary(dataLibraryPath);
            this.Name = dataLibraryPath;
        }

        public void SaveDataLibrary(string filePath)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<PlantData>)); 
            var writer = new StreamWriter(filePath);
            serializer.Serialize(writer, this._plants);
        }

        public void LoadDataLibrary(string filePath)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<PlantData>));
            var reader = new StreamReader(filePath);
            this._plants = serializer.Deserialize(reader) as List<PlantData>;
        }

        public List<PlantData> GetSuitablePlants(int humidity)
        {
            return this._plants.Where(plant => plant.MinHumidity <= humidity && plant.MaxHumidity >= humidity).ToList();
        } 
            
    }
}

